package com.tengju.bff.infrastructure.export.convert;

import com.tengju.bff.interfaces.covercharge.constant.SignIdentityEnum;
import com.tengju.bff.interfaces.covercharge.entity.vo.PersonalGiveVo;
import com.tengju.bff.interfaces.covercharge.util.DateTimeUtils;
import com.tengju.export.domain.record.Table;
import org.springframework.util.CollectionUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: 李大仙
 * @date: 2021/8/26 8:40 下午
 */
public class PersonalGiveConvert {
    public static Table convert(List<PersonalGiveVo> list, String authType) {
        Table table = new Table();
        table.setHeader(buildHeader(authType));
        table.setRecords(buildRecords(list, authType));
        return table;
    }

    private static List<List<String>> buildRecords(List<PersonalGiveVo> list, String authType) {
        List<List<String>> result = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)){
            return result;
        }
        int index = 1;
        if (SignIdentityEnum.person.getCode().equals(authType)) {
            DecimalFormat df2 = new DecimalFormat("#.00");
            for (PersonalGiveVo personalGiveVo : list) {
                List<String> row = new ArrayList<>();
                row.add(personalGiveVo.getIdcardName());
                row.add(personalGiveVo.getIdcardNo());
                row.add(personalGiveVo.getBankName());
                row.add(personalGiveVo.getBankNo());
                row.add(df2.format(personalGiveVo.getMoney()));
                row.add("");
                result.add(row);
                index++;
            }
        } else {
            for (PersonalGiveVo personalGiveVo : list) {
                List<String> row = new ArrayList<>();
                String updateTime = personalGiveVo.getUpdateTime() == null ? "" : DateTimeUtils.parseDateAsString(personalGiveVo.getUpdateTime(), DateTimeUtils.DEFAULT_DATE_TIME_FORMAT);
                row.add(index + "");
                row.add(personalGiveVo.getCycleDate());
                row.add(personalGiveVo.getIdCode() + "");
                row.add(personalGiveVo.getName());
                row.add(personalGiveVo.getMobile());
                row.add(personalGiveVo.getAuthType());
                row.add(personalGiveVo.getIdcardName());
                row.add(personalGiveVo.getBankName());
                row.add(personalGiveVo.getBankNo());
                row.add(personalGiveVo.getIdcardNo());
                row.add(personalGiveVo.getMerchantName());
                row.add(personalGiveVo.getMerchantTaxNumber());
                row.add(personalGiveVo.getApplyMoney().toString());
                row.add(personalGiveVo.getPassMoney().toString());
                row.add(personalGiveVo.getRatio().toString());
                row.add(personalGiveVo.getFee().toString());
                row.add(personalGiveVo.getMoney().toString());
                row.add(personalGiveVo.getStatusStr());
                row.add(personalGiveVo.getRemark());
                row.add(personalGiveVo.getBankFlow());
                row.add(personalGiveVo.getChannel());
                row.add(personalGiveVo.getCommon());
                row.add(personalGiveVo.getLetaxStatusStr());
                row.add(updateTime);
                row.add(personalGiveVo.getOperator());
                result.add(row);
                index++;
            }
        }
        return result;
    }

    private static List<String> buildHeader(String authType) {
        List<String> headerList = new ArrayList<>();
        if (SignIdentityEnum.person.getCode().equals(authType)) {
            headerList.add("姓名");
            headerList.add("身份证号");
            headerList.add("银行简称（不含开户行）");
            headerList.add("银行账号");
            headerList.add("结算服务费（最多保留2位小数）");
            headerList.add("企业备注");
        } else {
            headerList.add("序号");
            headerList.add("所属周期");
            headerList.add("代理ID");
            headerList.add("代理姓名");
            headerList.add("手机号");
            headerList.add("合作方式");
            headerList.add("户名");
            headerList.add("开户行");
            headerList.add("银行卡号");
            headerList.add("身份证号");
            headerList.add("个体工商户名称");
            headerList.add("税号");
            headerList.add("待审核金额");
            headerList.add("已审核金额");
            headerList.add("手续费率");
            headerList.add("手续费");
            headerList.add("应付金额");
            headerList.add("发放状态");
            headerList.add("备注");
            headerList.add("打款网银流水");
            headerList.add("打款渠道");
            headerList.add("共用注册个体户");
            headerList.add("乐税注销状态");
            headerList.add("更新时间");
            headerList.add("操作人");
        }
        return headerList;
    }
}
